<template>
  <div>
    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='addPollute()' type='primary' icon='plus'>新增污染大类</a-button>
      <a-button @click='addQx()' type='primary' icon='plus'>新增去向单位</a-button>
      <a-button @click='editPollute()' type='primary' icon='plus'>编辑污染大类</a-button>
    </div>

    <a-table
      ref='table'
      size='middle'
      bordered
      :rowKey="record => record.qxId"
      childrenColumnName='childrenColumnName'
      :columns='columns'
      :dataSource='dataSource'
      :pagination="false"
    >
      <span slot='action' slot-scope='text, record,index'>
<!--            <a v-if='text.status===1' @click='changeStatus(record.id,index)'>停用</a>-->
<!--            <a v-else @click='changeStatus(record.id,index)'>启用</a>-->
            <a-divider type='vertical' />
            <a @click='handleEdit(record)'> 编辑 </a>
            <a-divider type='vertical' />
            <a @click='handleDel(record.qxId)'> 删除 </a>
      </span>

    </a-table>
    <AddPolluteModal ref='addPolluteModal' v-on:loading="loading"></AddPolluteModal>
    <AddQxModal ref='addQxModal' v-on:loading="loading"></AddQxModal>
    <EditPolluteQxModal ref='editPolluteQxModal' v-on:loading="loading"></EditPolluteQxModal>
    <EditPolluteModal ref='editPolluteModal' v-on:loading="loading"></EditPolluteModal>
  </div>
</template>
<script>
import AddPolluteModal from '@views/epa/epa-statistics/Modal/AddPolluteModal'
import AddQxModal from '@views/epa/epa-statistics/Modal/AddQxModal'
import EpaSortService from '@/myService/EpaSortService'
import EditPolluteQxModal from '@views/epa/epa-statistics/Modal/EditPolluteQxModal'
import EditPolluteModal from '@views/epa/epa-statistics/Modal/EditPolluteModal'
export default {
  name: 'EpaStatisticsCategoryTemplate',
  components:{
    AddPolluteModal,
    AddQxModal,
    EditPolluteQxModal,
    EditPolluteModal
  },
  data() {
    return {
      dataSource:[],
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: (text, row, index) => 1 + index
        },
        {
          title: '污染大类',
          dataIndex: 'polluteName',
          align: 'center'
        },
        {
          title: '去向单位',
          dataIndex: 'qx',
          align: 'center'
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  created() {
    this.loading();
  },
  methods:{
    editPollute(){
      this.$refs.editPolluteModal.open()
    },
    handleEdit(record){
      this.$refs.editPolluteQxModal.open(record);
    },
    handleDel(qxId){
      EpaSortService.deleteSortQxFalse({id:qxId}).then((res)=>{
        if(res.result==1){
          this.$message.success("删除成功")
          this.loading()
        }
      })
    },
    addPollute(){
      this.$refs.addPolluteModal.open()
    },
    changeStatus(){
        console.log(this.dataSource)
    },
    addQx(){
      this.$refs.addQxModal.open()
    },
    loading(){
      console.log("刷新去向单位模板")
      EpaSortService.getSortPolluteQx().then((res)=>{
        console.log(res)
        this.dataSource=res.result
      })
    }
  }
}
</script>

<style scoped>

</style>